package com.abc.controller;

import com.abc.common.Result;
import com.abc.dto.response.FileUploadResponseDto;
import com.abc.service.FileUploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


/**
 * 文件上传控制器
 */
@Slf4j
@RestController
@RequestMapping("/file")
@Tag(name = "文件上传", description = "文件上传相关接口")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "上传文件", description = "上传单个文件到MinIO存储")
    public Result<FileUploadResponseDto> uploadFile(@RequestParam("file") MultipartFile file) {
        log.info("开始上传文件: {}", file.getOriginalFilename());
        FileUploadResponseDto response = fileUploadService.uploadFile(file);
        return Result.success(response);
    }
}
